
/**
 * @author weim
 * @date 18-8-27
 */
public class MyString {

    public static void main(String[] args) {

        //不可变类  final修饰
        String a = "aaa";
        String b = "bbb";

        String atemp = "aa" + "a";
        System.out.println(a == atemp);
        System.out.println(a.equals(atemp));

        String atemp1 = "aa" + new String("a");
        System.out.println(a == atemp1);
        System.out.println(a.equals(atemp1));


        String aa = new String("aaa");
        String bb = "bbb";

        System.out.println(a == aa);
        System.out.println(a.equals(aa));

        System.out.println(b == bb);
        System.out.println(b.equals(bb));

        //synchronized 线程安全的 可变
        StringBuffer sa = new StringBuffer("aaa");
        System.out.println(sa.equals(a));

        //不是线程安全的  可变
        StringBuilder builder = new StringBuilder("aaa");
        System.out.println(builder.equals(a));

    }

}
